package main

import "fmt"

func main() {

	index := findIndex("caabc", "ab")
	fmt.Println(index)
}

/*
*
cabc , ab
*/
func findIndex(str, sub string) int {

	j := 0
	tstr := ""
	index := -1
	for i := 0; i < len(str)-1; i++ {
		if str[i] == sub[j] {
			tstr = tstr + string(str[i])
			if j == 0 {
				index = i
			}
			j++

		} else {
			tstr = ""
			j = 0
			index = -1
			if str[i] == sub[j] {
				tstr = tstr + string(str[i])
				if j == 0 {
					index = i
				}
				j++

			}
		}
		if tstr == sub {
			return index
		}
	}
	return index
}
